package com.eningqu.aipen.ui.vedio;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.eningqu.aipen.MyApplication;
import com.eningqu.aipen.demo.R;
import com.eningqu.aipen.demo.databinding.ActivityVideoDetailBinding;
import com.eningqu.aipen.ui.base.BaseActivity;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import com.kongzue.dialogx.dialogs.MessageDialog;
import com.kongzue.dialogx.dialogs.PopTip;

/**
 * Package:com.eningqu.aipen.ui.vedio
 * Author:starr
 * Time:11/26/2023 4:29 PM
 * Description:
 */
public class VideoDetailActivity extends BaseActivity<ActivityVideoDetailBinding> {


    SimpleExoPlayer player;

    public static void startAction(Context context) {
        Intent intent = new Intent(context, VideoDetailActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_video_detail;
    }

    @Override
    protected void initView() {

        mBinding.setClick(new VideoClick());

//        String pathvideo = "https://db.workercn.cn/media/2023/11/24/C59F0545B3FB46E2BF9BC544B8E891B6/preview.mp4";
        StyledPlayerView playerView = mBinding.playView;
        player = new SimpleExoPlayer.Builder(playerView.getContext()).build();
        playerView.setPlayer(player);
        Uri uri = RawResourceDataSource.buildRawResourceUri(R.raw.preview);
        MediaItem item = MediaItem.fromUri(uri);
        player.setMediaItem(item);
        player.prepare();
    }

    @Override
    protected void initData() {



    }

    @Override
    protected void async() {

    }

    @SuppressWarnings("unused")
    public class VideoClick {
        public void back(View view) {
            finish();
        }

        //我的笔记
        public void myNote(View view){
            MessageDialog.show("我的笔记","神医在世，你还没有笔记哦，快快学习吧","确定");
        }

        //添加笔记
        public void addNote(View view){
            if(MyApplication.isConnect==-1){
                PopTip.tip("请先连接智能点阵笔....");
            }else{
                Bundle bundle=new Bundle();
                NoteActivity.startAction(getContext(),bundle);
            }
        }

    }

    @Override
    protected void onPause() {
        super.onPause();
        if(player!=null){
            player.pause();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(player!=null){
            player.stop();
            player.release();
        }

    }
}
